/*
 * Main.java
 *
 * Created on Mar 19, 2009, 8:59:51 AM
 */
package basicform;

import ca.beq.util.win32.registry.RegistryKey;
import ca.beq.util.win32.registry.RegistryValue;
import ca.beq.util.win32.registry.RootKey;
import java.awt.Desktop;
import java.io.FileFilter;
import java.util.Locale;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.filechooser.FileNameExtensionFilter;


/**
 *
 * @author georgev
 */
public class Main extends javax.swing.JFrame {
	public static final String DISPLAY_KEY  = "\\http\\shell\\open\\command";
    /** Creates new form Main */
    public Main() {
        initComponents();
    }

    public void getBrowserPath() {
        System.out.print("just before reg");
        RegistryKey displays = new RegistryKey(RootKey.HKEY_CLASSES_ROOT, DISPLAY_KEY);
        System.out.println("after reg");

//        if(displays.hasValues()) {
//Iterator i = displays.values();
//while(i.hasNext()) {
//RegistryValue x = (RegistryValue)i.next();
//System.out.println(x.getName());
//System.out.println(x.getStringValue());
//System.out.println(x.toString());
//} // while
//} // if


//        if( displays.hasValue("Default") ) {
            RegistryValue value = displays.getValue("");
            String hardware = value.getStringValue().trim().toUpperCase(Locale.ENGLISH);
            System.out.println(hardware);
//        }
    }

    public static void openURL(String url) { 
        try{
        Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandler " + url);
        }
        catch (Exception e) {
            String errMsg = "Error attempting to launch web browser";
            JOptionPane.showMessageDialog(null, errMsg + "\n" + e.toString());
        }
    }
    


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        openFormButton = new javax.swing.JButton();
        testButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        helpButton = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jToggleButton1 = new javax.swing.JToggleButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setForeground(new java.awt.Color(255, 255, 51));

        openFormButton.setText("OpenForm");
        openFormButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openFormButtonActionPerformed(evt);
            }
        });

        testButton.setText("Test");
        testButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                testButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 420, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 413, Short.MAX_VALUE)
        );

        helpButton.setText("Help");
        helpButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpButtonActionPerformed(evt);
            }
        });

        jButton1.setText("Cancel");

        jButton2.setText("Ok");

        jToggleButton1.setText("jToggleButton1");
        jToggleButton1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jToggleButton1ItemStateChanged(evt);
            }
        });

        jMenu1.setText("File");

        jMenuItem2.setText("jMenuItem2");
        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");

        jMenuItem1.setText("jMenuItem1");
        jMenu2.add(jMenuItem1);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(testButton)
                        .addGap(18, 18, 18)
                        .addComponent(openFormButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jToggleButton1))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(192, 192, 192)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(helpButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(testButton)
                    .addComponent(openFormButton)
                    .addComponent(jToggleButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(helpButton)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void openFormButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openFormButtonActionPerformed

}//GEN-LAST:event_openFormButtonActionPerformed

    private void testButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_testButtonActionPerformed
FileFilter fileFilter;
FileNameExtensionFilter fil;
        
        boolean stop = true;
    }//GEN-LAST:event_testButtonActionPerformed

    private void helpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpButtonActionPerformed
        if( Desktop.isDesktopSupported() ) {
            Desktop desktop = Desktop.getDesktop();
            try {
//                URL url = getClass().getResource("/html/intro.html");
//                URI uri = new URI("file","C:/Users/gvarghese/Documents/book/build/html/intro.html","motivation");
//                URI uri = new URI("file","C:\\Users\\gvarghese\\Documents\\book\\build\\html\\conclusion.html","future");
//                URI uri = new URI("file","C:/Users/gvarghese/Documents/book/build/html/intro.html","motivation");
//                URI uri = new URI("http://sphinx.pocoo.org/tutorial.html#basic-configuration");
//                  URI uri = new URI("http","sphinx.pocoo.org/tutorial.html","basic-configuration");
//                String abc = uri.getFragment();
//                URI uri = url.toURI();
//                openURL("\"" +uri.toString()+"\"");
//                desktop.browse(uri);
                 getBrowserPath();

            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
    }//GEN-LAST:event_helpButtonActionPerformed

    private void jToggleButton1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jToggleButton1ItemStateChanged
        jToggleButton1.isSelected();
    }//GEN-LAST:event_jToggleButton1ItemStateChanged

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (Exception e) {
            e.printStackTrace();
        }


        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                Main main = new Main();
                main.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton helpButton;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JButton openFormButton;
    private javax.swing.JButton testButton;
    // End of variables declaration//GEN-END:variables
}
